home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
ARGONET
/
PD
/
GAMES
/
WIMPGAME
/
MINES2.ZIP
/
!Mines
/
c
/
HintATest
< prev
next >
Wrap
Text File
|
1995-02-03
|
4KB
|
128 lines
/* Testrahmen f"ur die Asseblerprozedur
** test_if_possible
*/
typedef struct {char x,y,domain;int test;} border_typ;
#include <stdio.h>
#include "HintA.h"
#define FALSE 0
#define TRUE 1
#define XMAX 30
#define YMAX 16
int feld[XMAX][YMAX];
border_typ b;
#define MINE 1
#define MARK 2
#define CLOSED 4
int off[8][2] = { {-1,-1},{0,-1},{1,-1},{-1,0},{1,0},{-1,1},{0,1},{1,1}};
#define in_playground(x,y) (((x)>=0) && ((x)<XMAX) && ((y)>=0) && ((y)<YMAX))
int c_test_if_possible(border_typ *border_ptr)
{
/* Testet, ob die Wahl dieses Feldes gegen Informationen
der Nachbarfelder verstoesst */
char d0,d1,mines,marks,x1,y1;
for (d0=0;d0<8;d0++)
{
x1=border_ptr->x+off[d0][0];
y1=border_ptr->y+off[d0][1];
if (in_playground(x1,y1) && !(feld[x1][y1] & CLOSED))
{
mines=0;marks=0;
for (d1=0;d1<8;d1++)
{
char x2=x1+off[d1][0],y2=y1+off[d1][1];
if (in_playground(x2,y2))
{
register char f=feld[x2][y2];
if (f & MINE) mines++;
if (f & MARK) marks++;
}
}
if ((border_ptr->test & (1 << d0))!=0)
{ if (marks>mines) return FALSE; }
else { if (marks!=mines) return FALSE; }
}
}
return(TRUE);
}
void do_tip(void)
{
FILE *f;
int x,y;
if ((f=fopen("<Mines$Dir>.tip","rb"))==0) return;
while (!feof(f)) {
fread(&b,4,sizeof(char),f);
for (x=-2;x<=2;x++) for (y=-2;y<=2;y++)
if (in_playground(b.x+x,b.y+y)) fread(&(feld[b.x+x][b.y+y]),1,sizeof(int),f);
for (y=-2;y<=2;y++)
{
for (x=-2;x<=2;x++) if (in_playground(b.x+x,b.y+y)) printf("%3x",feld[b.x+x][b.y+y]); else printf(" . ");
printf("\n");
}
if (c_test_if_possible(&b)) printf("TRUE "); else printf("FALSE ");
if (test_if_possible(&b,XMAX,YMAX,(char *)feld)) printf("TRUE\n"); else printf("FALSE\n");
}
fclose(f);
}
void brute_force(void)
{
int x0,y0,d0,and,or,m,d1,i;
int x[25]={2,2,2,1,3,1,1,3,3,0,0,0,0,0,1,1,2,2,3,3,4,4,4,4,4},
y[25]={2,1,3,2,2,1,3,1,3,0,1,2,3,4,0,4,0,4,0,4,0,1,2,3,4},
fx[5]={0,1,15,28,29},fy[5]={0,1,8,14,15},
prev[8]={0,0,1,5,2,6,7,4};
for (i=0;i<25;i++)
{
printf("%i ",i);
x0=fx[x[i]];y0=fy[y[i]];
b.x=x0;b.y=y0;b.test=0;
for (d0=0;d0<8;d0++)
{
int x1=x0+off[d0][0],y1=y0+off[d0][1],
x2=x0+off[prev[d0]][0],y2=y0+off[prev[d0]][1];
if (!in_playground(x1,y1) || !in_playground(x2,y2)) continue;
feld[x1][y1]&=~CLOSED;feld[x2][y2]&=~CLOSED;
and=0xFFFF;or=0;
for (m=0;m<65536;m++)
{
for (d1=0;d1<8;d1++)
{
int x2=x1+off[d1][0],y2=y1+off[d1][1];
if (in_playground(x2,y2) && (!(feld[x2][y2] & CLOSED)))
{
if (m & (1 << d1)) feld[x2][y2]|=MINE;
else feld[x2][y2]&=~MINE;
if (m & (1 << (d1+8))) feld[x2][y2]|=MARK;
else feld[x2][y2]&=~MARK;
}
}
if (c_test_if_possible(&b)!=test_if_possible(&b,XMAX,YMAX,feld))
{ and&=m;or|=m;}
}
feld[x1][y1]|=CLOSED;feld[x2][y2]|=CLOSED;
if ((and!=0xFFFF) || (or!=0))
{
printf("x:%i y:%i d0:%i and: %4x or: %4x\n",x0,y0,d0,and,or);
}
}
printf("\n");
}
}
int main(void)
{
border_typ b;
/*brute_force();*/
printf("%i %i",sizeof(border_typ),(char *)&b.test - (char *)&b);
return 0;
}